<?php
/**
 * SchoolRoom Model
 *
 * Utilizes the Data Mapper pattern to persist data. Represents a single
 * school_room entry
 *
 * @version $Id: SchoolRoom.php 73 2010-04-25 00:30:44Z yingkuang.chen@gmail.com $
 * @license New BSD License
 * @uses School_Model_SchoolRoomMapper
 * @package school
 * @subpackage Model
 */
class School_Model_SchoolRoom extends School_Model_Doctrine_BaseSchoolRoom
{


    /**
     * 取得處室下的職稱
     * @return unknown_type
     */
    public function getParentCount()
    {
        $q = Doctrine_Query::create()
        ->select('t.division_sn ,COUNT(DISTINCT t.sn) AS cc')
        ->from('Teacher_Model_TeacherTitle t')
        ->leftJoin('School_Model_SchoolRoom r')
        ->groupBy('t.division_sn');

        $res = $q->fetchArray();

        $arr = array();
        foreach($res as $row) {
            $arr[$row['division_sn']] = $row['cc'];
        }
        return $arr;
    }


    public function  getKind() {
        $arr = array();

        $q = Doctrine_Query::create()
                ->select('sn, name')
                ->from('School_Model_SchoolRoom')
                ->where('enable=?','Y');
        $data = $q->fetchArray();

        foreach ($data as $row) {
            $arr[$row['sn']] = $row['name'];
        }
        return $arr;
    }

}
